<script setup>
import { useRouter } from 'vue-router'
import { Unlock } from '@element-plus/icons-vue'
import SunComponent from '@/components/SunComponent.vue'
import BackButton from '@/components/BackButton.vue'
import WarnIcon from '@/components/icons/WarnIcon.vue'
import LadderIcon from '@/components/icons/LadderIcon.vue'
import CoinIcon from '@/components/icons/CoinIcon.vue'
import fetchCoin from '@/utils/fetchCoin'
import { onMounted, ref } from 'vue'
import BackgroundImage from '@/components/BackgroundImage.vue'

const coins = ref(0)
const router = useRouter()

const enterPart3Game = (difficulty) => {
  router.push({ name: 'part3-game', query: { difficulty } })
}

onMounted(async () => {
  coins.value = await fetchCoin()
})
</script>
<template>
  <div class="container">
    <background-image />
    <div class="coin">
      <coin-icon :size="64" />
      <span style="font-size: 36px; margin-left: 8px; color: white">{{ coins }}</span>
    </div>
    <back-button
      style="position: absolute; top: 20px; left: 20px; z-index: 101"
      @click="router.push({ name: 'game-select' })"
    />
    <sun-component class="sun" />
    <div class="center">
      <div class="train">
        <div class="engine-front">
          <div class="chimney">
            <div class="smoke"></div>
            <div class="smoke smoke-2"></div>
            <div class="smoke smoke-3"></div>
            <div class="smoke smoke-4"></div>
          </div>
        </div>
        <div class="engine-body"></div>
        <div class="compartment fuel-compartment">
          <warn-icon :size="48" />
          <ladder-icon :size="60" />
        </div>
        <div class="compartment wagon-compartment">
          <div class="compartment-window"></div>
        </div>
        <div class="compartment tail-compartment">
          <div class="compartment-no-window"></div>
          <div class="tail"></div>
        </div>
        <div class="wheel-holder">
          <div class="wheel"></div>
          <div class="wheel wheel-2">
            <div class="wheel-joint"></div>
            <div class="wheel-joint wheel-joint-2"></div>
          </div>
          <div class="wheel wheel-3"></div>
          <div class="wheel wheel-4"></div>
          <div class="wheel wheel-5"></div>
          <div class="wheel wheel-6"></div>
          <div class="wheel wheel-7"></div>
          <div class="wheel wheel-8"></div>
          <div class="wheel wheel-9"></div>
        </div>
      </div>
      <div class="bridge"></div>
    </div>
    <div
      style="
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        display: flex;
        flex-direction: column;
        z-index: 100;
        padding: 128px 80px 80px 80px;
      "
    >
      <div style="display: flex; gap: 40px; flex: 1; justify-content: center">
        <div>
          <h1 style="font-size: 40px; text-align: center; white-space: nowrap">简单</h1>
          <div
            class="base-border"
            style="height: 70%; display: flex; align-items: center; justify-content: center"
            @click="enterPart3Game(0)"
          >
            <unlock color="white" style="width: 80%" />
          </div>
        </div>
        <div>
          <h1 style="font-size: 40px; text-align: center; white-space: nowrap">困难</h1>
          <div
            class="base-border"
            style="height: 70%; display: flex; align-items: center; justify-content: center"
            @click="enterPart3Game(2)"
          >
            <unlock color="white" style="width: 80%" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
@import '@/styles/base-train.css';

.sun {
  top: 10%;
  left: 20%;
  position: absolute;
}

.buttons {
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

.base-border {
  background-color: #ffe2b3;
  border: 6px solid #f55a36;
  font-size: 28px;
  border-radius: 20px;
}

.coin {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
